<template>
  <nav
    id="myheader"
    :style="{ background: bgColor }"
    :class="[transparent ? 'yellow' : '', follow ? 'follow' : '']"
  >
    <section @click="back" class="back-container">
      <i :class="['backIcon', backW ? 'white' : '']" v-show="backStatus"></i>
    </section>
    <slot></slot>
    <section class="right" @click="preview">
      <i :class="['rightText', backW ? 'white' : '']" v-show="rightText">{{
        rightText
      }}</i>
    </section>
  </nav>
</template>

<script>
export default {
  name: 'Myheader',
  props: ['backUrl', 'backStatus', 'selfFn', 'rightText', 'previewQuestin', 'preserve', 'bgColor', 'transparent', 'follow', 'backW'],
  data() {
    return {}
  },
  methods: {
    back() {
      if (this.selfFn) {
        this.selfFn()
      } else {
        if (this.backUrl === '/') {
          // alert(1)
          this.$router.back()
          // this.$router.push({ path: this.backUrl })
        } else {
          this.$router.push({ path: this.backUrl })
        }
      }
    },
    preview() {
      this.$emit('sopreviewQuestin')
    }
  },
  created() {

  }
}
</script>

<style lang="scss">
#myheader {
  height: rem(88);
  width: 100%;
  line-height: rem(88);
  font-size: rem(34);
  font-weight: bold;
  background: #fff;
  background-size: 100% rem(88);
  color: #333333;
  position: absolute;
  top: 0;
  left: 0;
  text-align: center;
  &.follow {
    @include bg-color($mainColor);
    color: #fff;
  }
  &.yellow {
    background: #eb523c;
    color: #fff;
  }
  .back-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 20%;
    height: 100%;
    .backIcon {
      width: rem(22);
      height: rem(38);
      background: url("../assets/images/back-b.png") no-repeat;
      background-size: rem(22) rem(38);
      display: inline-block;
      position: absolute;
      top: rem(24);
      left: rem(24);
      &.white {
        background: url("../assets/images/back-w.png") no-repeat;
        width: rem(22);
        height: rem(38);
        background-size: rem(22) rem(38);
        display: inline-block;
        position: absolute;
        top: rem(24);
        left: rem(24);
      }
    }
  }
  .right {
    display: inline-block;
    position: absolute;
    right: rem(24);
    .rightText {
      font-size: rem(30);
      font-family: PingFang SC;
      font-weight: 600;
      color: rgba(0, 0, 48, 1);
      &.white {
        color: #fff;
      }
    }
  }
}
</style>
